package cn.amoqi.springbootrocketmq2.index;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description:
 * @author: zhuiFeng
 * @date: 2021年06月10日 15:15
 */
@RestController
public class IndexController {
    @Resource
    private RocketMQTemplate rocketMQTemplate;

    @RequestMapping
    public void index(){
        rocketMQTemplate.convertAndSend("test-topic-2", "Hello, World!");
        rocketMQTemplate.send("test-topic-2", MessageBuilder.withPayload("Hello, World! I'm from spring message").build());
    }
    @Slf4j
    @Service
    @RocketMQMessageListener(topic = "test-topic-2", consumerGroup = "my-consumer_test-topic-1")
    public static class MyConsumer1 implements RocketMQListener<String> {
        public void onMessage(String message) {
            log.info("received message: {}", message);
        }
    }
}
